#ifndef __BSP_UART_H
#define __BSP_UART_H

#include "bsp.h"


#if HardwareType == Common_Hardware_Type

#define UartHandle_Print UART1Handle


//串口1
//TX    PB6
//RX    PB7
#define UART1_TX_PORT               GPIOB
#define UART1_TX_PIN                GPIO_PIN_6
#define UART1_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOB_CLK_ENABLE

#define UART1_RX_PORT               GPIOB
#define UART1_RX_PIN                GPIO_PIN_7
#define UART1_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOB_CLK_ENABLE

//串口2
//TX    PA2
//RX    PA3
#define UART2_TX_PORT               GPIOA
#define UART2_TX_PIN                GPIO_PIN_2
#define UART2_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOA_CLK_ENABLE

#define UART2_RX_PORT               GPIOA
#define UART2_RX_PIN                GPIO_PIN_3
#define UART2_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOA_CLK_ENABLE


//串口3
//TX    PC10
//RX    PC11
#define UART3_TX_PORT               GPIOC
#define UART3_TX_PIN                GPIO_PIN_10
#define UART3_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE

#define UART3_RX_PORT               GPIOC
#define UART3_RX_PIN                GPIO_PIN_11
#define UART3_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE


//串口4
//TX    PA0
//RX    PA1
#define UART4_TX_PORT               GPIOA
#define UART4_TX_PIN                GPIO_PIN_0
#define UART4_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOA_CLK_ENABLE

#define UART4_RX_PORT               GPIOA
#define UART4_RX_PIN                GPIO_PIN_1
#define UART4_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOA_CLK_ENABLE


//串口5
//TX    PC12
//RX    PD2
#define UART5_TX_PORT               GPIOC
#define UART5_TX_PIN                GPIO_PIN_12
#define UART5_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE

#define UART5_RX_PORT               GPIOD
#define UART5_RX_PIN                GPIO_PIN_2
#define UART5_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOD_CLK_ENABLE


//串口6
//TX    PC6
//RX    PC7
#define UART6_TX_PORT               GPIOC
#define UART6_TX_PIN                GPIO_PIN_6
#define UART6_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE

#define UART6_RX_PORT               GPIOC
#define UART6_RX_PIN                GPIO_PIN_7
#define UART6_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE


extern UART_HandleTypeDef UART1Handle;
extern UART_HandleTypeDef UART2Handle;
extern UART_HandleTypeDef UART3Handle;
extern UART_HandleTypeDef UART4Handle;
extern UART_HandleTypeDef UART5Handle;
extern UART_HandleTypeDef UART6Handle;


#define RC_FRAME_LENGTH     18u
#define POWER_DATA_LENGTH   9
#define GYRO_DATA_MAX       	55u
#define GYRO_ANGLE_DATA_LEN 	25u
#define GYRO_ANGV_DATA_LEN  	49u

extern uint8_t uart1_rx_data;
extern uint8_t uart2_rx_data;
//extern uint8_t uart3_rx_data[2][POWER_DATA_LENGTH];
extern uint8_t uart3_rx_data[POWER_DATA_LENGTH];
extern uint8_t uart4_rx_data[2][RC_FRAME_LENGTH];
extern uint8_t uart5_rx_data[2][55u];
extern uint8_t uart6_rx_data;

extern DMA_HandleTypeDef hdma_u2tx;

void UART1_Init(uint32_t boundrate);
void UART2_Init(uint32_t boundrate);
void UART3_Init(uint32_t boundrate);
void UART4_Init(uint32_t boundrate);
void UART5_Init(uint32_t boundrate);
void UART6_Init(uint32_t boundrate);

void BSP_UART1_RX_Callback(uint8_t rxdata);
void BSP_UART2_RX_Callback(uint8_t rxdata);
void BSP_UART3_RX_Callback(uint8_t rxdata[]);
void BSP_UART4_RX_Callback(uint8_t rxdata[]);
void BSP_UART5_RX_Callback(uint8_t rxdata[]);
void BSP_UART6_RX_Callback(uint8_t rxdata);

void MY_UART_IRQHandler(UART_HandleTypeDef* huart);





#elif HardwareType == Engineer_Hardware_Type

#define UartHandle_Print UART5Handle//无线


//串口1
//TX    PA9
//RX    PA10
#define UART1_TX_PORT               GPIOA
#define UART1_TX_PIN                GPIO_PIN_9
#define UART1_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOA_CLK_ENABLE

#define UART1_RX_PORT               GPIOA
#define UART1_RX_PIN                GPIO_PIN_10
#define UART1_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOA_CLK_ENABLE

//串口2
//TX    PA2
//RX    PA3
#define UART2_TX_PORT               GPIOA
#define UART2_TX_PIN                GPIO_PIN_2
#define UART2_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOA_CLK_ENABLE

#define UART2_RX_PORT               GPIOA
#define UART2_RX_PIN                GPIO_PIN_3
#define UART2_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOA_CLK_ENABLE


//串口3
//TX    PB10
//RX    PB11
#define UART3_TX_PORT               GPIOB
#define UART3_TX_PIN                GPIO_PIN_10
#define UART3_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOB_CLK_ENABLE

#define UART3_RX_PORT               GPIOB
#define UART3_RX_PIN                GPIO_PIN_11
#define UART3_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOB_CLK_ENABLE


//串口4
//TX    PC10
//RX    PC11
#define UART4_TX_PORT               GPIOC
#define UART4_TX_PIN                GPIO_PIN_10
#define UART4_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE

#define UART4_RX_PORT               GPIOC
#define UART4_RX_PIN                GPIO_PIN_11
#define UART4_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE


//串口5
//TX    PC12
//RX    PD2
#define UART5_TX_PORT               GPIOC
#define UART5_TX_PIN                GPIO_PIN_12
#define UART5_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE

#define UART5_RX_PORT               GPIOD
#define UART5_RX_PIN                GPIO_PIN_2
#define UART5_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOD_CLK_ENABLE


//串口6
//TX    PC6
//RX    PC7
#define UART6_TX_PORT               GPIOC
#define UART6_TX_PIN                GPIO_PIN_6
#define UART6_TX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE

#define UART6_RX_PORT               GPIOC
#define UART6_RX_PIN                GPIO_PIN_7
#define UART6_RX_PORT_CLK_ENABLE    __HAL_RCC_GPIOC_CLK_ENABLE

extern DMA_HandleTypeDef hdma_u3tx;

extern UART_HandleTypeDef UART1Handle;
extern UART_HandleTypeDef UART2Handle;
extern UART_HandleTypeDef UART3Handle;
extern UART_HandleTypeDef UART4Handle;
extern UART_HandleTypeDef UART5Handle;
extern UART_HandleTypeDef UART6Handle;

#define RC_FRAME_LENGTH     	18u

#define GYRO_DATA_MAX       	55u
#define GYRO_ANGLE_DATA_LEN 	25u
#define GYRO_ANGV_DATA_LEN  	49u

extern uint8_t uart1_rx_data[2][RC_FRAME_LENGTH];
extern uint8_t uart2_rx_data;
extern uint8_t uart3_rx_data;
extern uint8_t uart4_rx_data[32];
extern uint8_t uart5_rx_data[2][55u];
extern uint8_t uart6_rx_data[2][GYRO_DATA_MAX];


void UART1_Init(uint32_t boundrate);
void UART2_Init(uint32_t boundrate);
void UART3_Init(uint32_t boundrate);
void UART4_Init(uint32_t boundrate);
void UART5_Init(uint32_t boundrate);
void UART6_Init(uint32_t boundrate);

void BSP_UART1_RX_Callback(uint8_t rxdata[]);
void BSP_UART2_RX_Callback(uint8_t rxdata);
void BSP_UART3_RX_Callback(uint8_t rxdata);
void BSP_UART4_RX_Callback(uint8_t rxdata[]);
void BSP_UART5_RX_Callback(uint8_t rxdata[]);
void BSP_UART6_RX_Callback(uint8_t rxdata[]);
void MY_UART_IRQHandler(UART_HandleTypeDef* huart);
#endif

#endif


